<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>$cacheFactory</title>
    <link rel="stylesheet" href="../../lib/bootstrap3/css/bootstrap.min.css">
    <script src="../../lib/angularjs/angular.js"></script>
</head>
<body ng-app="cacheApp">
    <div class="well">
        var cache = $cacheFactory('myCache');<br>
        cache.push(key,value);<br/>
        <p class="bg-danger">key:字符串类型</p>
        <p class="bg-danger">value:字符串类型、对象等各种类型</p>
    </div>
    <div class="well" ng-controller="ctrl01">
        <button class="bg-danger btn" ng-click="getName()">getName</button>
        <button class="bg-danger btn" ng-click="getName1()">getName1</button>
        <button class="bg-danger btn" ng-click="info()">info</button>
        <p class="bg-success">{{message}}</p>
    </div>
</body>
<script>
    var app=angular.module("cacheApp",[]);
    app.controller("ctrl01",["$cacheFactory","$scope",function ($cacheFactory,$scope) {
        var cache = $cacheFactory('myCache');
        $scope.message=="";
        function init() {
            if(cache.get("name")){
                alert("已存在");
            }else{
                cache.put("name","张三");
                cache.put("age","28");
            }
        }
        $scope.getName=function () {
            $scope.message=(cache.get("name"));
        }
        $scope.getName1=function () {
            $scope.message=(cache.get("name1"));
        }
        $scope.info=function () {
            var obj=cache.info();
            var objs=[];
            for(var i in obj){
                objs.push(i+":"+obj[i]);
            }
            $scope.message=(objs.join(","));
        }
        init();
    }]);
</script>
</html>